package gov.pbc.nn.kjgl.item.template.dao;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.bstek.dorado.util.proxy.ProxyBeanUtils;

import gov.pbc.nn.core.dao.AbstractHibernateDao;
import gov.pbc.nn.kjgl.item.template.entity.ItemType;
import gov.pbc.nn.kjgl.item.template.setting.ItemSetting;

/**
 * 事项审批的Dao
 * 
 * @author Administrator
 * 
 */
@Component
public class ItemApprovalDao extends AbstractHibernateDao {

	public ItemSetting convertToItemSetting(ItemType it) {
		String strJson = JSON.toJSONString(it, SerializerFeature.WriteDateUseDateFormat);
		ItemSetting itemSetting = JSON.parseObject(strJson, ItemSetting.class);
		itemSetting.setCode(it.getId());
		return itemSetting;
	}

	public ItemSetting getItemSeting(String itemTypeId) {
		ItemType it = this.get(itemTypeId, ItemType.class);
		return convertToItemSetting(it);

	}

	public ItemSetting getItemSeting(ItemType it) throws Exception {
		if (ProxyBeanUtils.isProxy(it)) {
			it = (ItemType) ProxyBeanUtils.getProxyTarget(it);
		}
		return convertToItemSetting(it);

	}

}
